<script>
/**
 * 用户管理
 * @author:Mumu
 * @date:
 */
import Mod from './contentWrite'
export default {
	components:{
		Mod
	},
	data(){
		return {
			field:[
			// 	{
			// 	title: '',
			// 	width:'30px',
			// 	slots: { customRender: 'checked' }
			// },
			{
				title: 'ID',
				width:'120px',
				dataIndex: 'id'
			},{
				title: '分类名称',
				dataIndex: 'name'
			},{
				title: '排序',
				dataIndex: 'sort'
			},
			{
				title: '操作',
				align: "center",
				width: "220px",
				dataIndex: 'action',
				fixed: 'right',
				slots: { customRender: 'action' }
			}],//表头
			list:[{}],//列表
			pagination: {
				defaultCurrent: 1,
				current: 1,
				defaultPageSize: 10,
				pageSize: 10,
				showQuickJumper: true,
				showSizeChanger: true,
				showTotal: (total, range) => `共${total}条`,
				total: 0,
			},
			listloading:false,
			search:{},
			rolelist:[],
			exportloading:false,
		}
	},
	mounted() {
		this.$nextTick(()=>{
			this.getList();
		})
	},
	methods:{
		async getList() {
			if(this.listloading) return;
			this.listloading		=	true;
			let rs	=	await this.muajax.classlist({
				...this.search,
				page:this.pagination.current,
				size:this.pagination.pageSize,
			});
			this.listloading		=	false;
			// if (rs.status!=200) return;
			if ( this.pagination.current == 1 ){
				this.records		=	[];
			}
			this.list=rs.list;
			this.pagination.total=rs.sum;
		},//列表
		async del(k){
			if(!await this.$showfirm('确定要删除该数据吗？')) return;
			let rs = await this.muajax.roleDel({
				ids:[this.list[k].id]
			});
			if(rs.code==200){
				this.$message.success('删除成功');
				if(this.list.length==1){
					this.research();
				}else{
					this.getList();
				}
			}
		},//删除
		research(){
			this.pagination.current=1;
			this.getList();
		},//搜索重置
		applysDataTableChangeHandle(pagination, filters, sorter,ee) {
			console.log(pagination, filters, sorter,ee)
			this.pagination.current		= pagination.current;
			this.pagination.pageSize	= pagination.pageSize;
			this.getList();
		},//操作分页控制
		async setstatus(e,item){
			if(item.loading) return
			item.loading		=	true;
			let rs	=	await this.muajax.setrole({
				id:item.id,
				status:e?1:0
			});
			item.loading = false
			if(rs.code==200){
				this.$message.success(rs.msg);
				this.getList();
			}
		},//设置角色状态
		update_list(){
			this.getList();
		},
	},
	computed: {

	},
}
</script>
<template>

	<a-card>
		<a-form layout="inline" class="text-center">
			<a-form-item label="搜索">
				<a-input
					v-model:value="search.keyword"
					placeholder="输入搜索内容"
					style="width:300px"
				/>
			</a-form-item>
			<a-form-item>
				<a-space>
					<a-button type="primary" @click="research()">搜索</a-button>
					<!-- <a-button type="primary" :loading="exportloading" @click="exportexcel()">导出结果</a-button> -->
					<!-- <a-button type="default">重置</a-button> -->
				</a-space>
			</a-form-item>
		</a-form>
		<div class="mm-t-20 mm-b-15">
			<a-space>
				<!--待开发 <a-button type="primary" danger>删除</a-button> -->
			</a-space>
		</div>

		<div class="mm-t-20 mm-b-15">
			<a-space>
				<a-button type="primary" @click="$refs.mod.show(true)">+ 新建</a-button>
				<!-- <a-button type="primary" danger>删除</a-button> -->
			</a-space>
		</div>
		
		<a-table
			:columns="field"
			:data-source="list"
			:pagination="pagination"
			:loading="listloading"
			:scrollToFirstRowOnChange="true"
			@change="applysDataTableChangeHandle"
			size="small"
			:row-key="(record)=>JSON.stringify(record)"
		>
			<template #checked="{record}">
				<a-checkbox v-model:checked="record.checked"></a-checkbox>
			</template>
			<template #head="{record}">
				<a-avatar :src="record.head" />
			</template>
			<template #iscompany="{record}">
				<a-switch checked-children="启用" un-checked-children="禁用" @change="e=>setstatus(e,record)" :checked="!!record.status" :loading="record.loading" />
			</template>

			<template #action="{record,index}">
				<a-button type="primary" size="small" @click="$refs.mod.show(true,record)">修改</a-button>
				<a-divider type="vertical" />
				<a-button type="primary" size="small" danger @click="del(index)">删除</a-button>
			</template>
		</a-table>
	</a-card>
	<Mod ref="mod" @update_list="update_list()" />
	<Authority ref="authority" @update_list="update_list()" />
</template>
<style lang="less" scoped>
.tabsort{
	width: 100%;
	height: 100%;
	cursor: pointer;
	.sortico{
		display: inline-flex;
	    flex-direction: column;
	    vertical-align: middle;
	    .anticon{
	    	margin: -2px;
	    	&.active{
	    		color: #00c4ff;
	    	}
	    }
	}
}
</style>